package com.xxxx.yeb.controller;


import com.xxxx.yeb.pojo.Position;
import com.xxxx.yeb.pojo.RespBean;
import com.xxxx.yeb.service.impl.PositionServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-07-17
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {

    @Autowired
    private PositionServiceImpl positionService;

    /**
     * 查询所有职位
     *
     * @return 所有职位
     */
    @ApiOperation(value = "查询所有职位")
    @GetMapping("/all")
    public List<Position> queryAllPosition() {
        return positionService.queryAllPosition();
    }

    @ApiOperation(value = "添加职位")
    @PostMapping("/byName")
    @Transactional(rollbackFor = Exception.class)
    public RespBean addPositionByName(@RequestBody Map<String, Object> map) {
        String name = (String) map.get("name");

        return positionService.addPositionByName(name);

    }

    /**
     * 编辑职位
     *
     * @param position
     * @return
     */
    @ApiOperation(value = "编辑职位")
    @PutMapping("/byPosition")
    @Transactional(rollbackFor = Exception.class)
    public RespBean updatePositionByPosition(@RequestBody Position position) {
        return positionService.updatePositionByPosition(position);
    }

    /**
     * 删除职位
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除职位")
    @DeleteMapping("/byIds")
    @Transactional(rollbackFor = Exception.class)
    public RespBean deleteBatchIds(Integer[] ids) {
        return positionService.deleteBatchIds(ids);
    }


}
